package com.ly.wxstore.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ly.wxstore.comm.MyPage;
import com.ly.wxstore.entity.TicketRecord;
import com.ly.wxstore.repository.TicketRecordDao;

/**
 * 
 * 
 * @author Peter
 */
// Spring Service Bean的标识.
@Component
public class TicketRecordService {

	private static Logger logger = LoggerFactory.getLogger(TicketRecordService.class);

	@Autowired
	private TicketRecordDao ticketRecordDao;

	public TicketRecord getById(Long id) {
		return ticketRecordDao.getById(id);
	}

	public List<TicketRecord> getAll() {
		return ticketRecordDao.getAll();
	}

	/**
	 * 分页查询
	 * 
	 * @param overtime
	 * @param pageStart
	 * @param pageSize
	 * @return
	 */
	public MyPage<TicketRecord> searchPage(TicketRecord ticketRecord, int currentPage, int pageSize) {
		MyPage<TicketRecord> myPage = new MyPage<TicketRecord>();

		Long count = ticketRecordDao.searchCount(ticketRecord);

		int pageStart = (currentPage - 1) < 0 ? 0 : (currentPage - 1) * pageSize;
		List<TicketRecord> list = ticketRecordDao.searchPage(ticketRecord, pageStart, pageSize);

		myPage.setCount(count);
		myPage.setContent(list);

		return myPage;
	}

	public void save(TicketRecord ticketRecord) {
		ticketRecordDao.save(ticketRecord);
	}

	public void update(TicketRecord ticketRecord) {
		ticketRecordDao.update(ticketRecord);
	}

	/**
	 * 软删除
	 */
	public void delete(Long id) {
		ticketRecordDao.delete(id);
	}
}
